package frameworks.modules
{
	import frameworks.controllers.BaseModuleController;
	import frameworks.models.BaseModel;
	import frameworks.modules.views.IBaseView;
	import frameworks.widgets.BaseSender;
	import frameworks.widgets.Result;
	import frameworks.widgets.ResultProxy;
	import frameworks.widgets.Watchers;

	public class BaseModule extends Watchers implements IBaseModule
	{
		private var _view:IBaseView;
		private var _options:Object;
		private var _id:String;
		private var _watchers:Watchers = new Watchers();
		private var _moduleController:BaseModuleController = Facade.SingleInstance().moduleController;
		
		public function BaseModule(id:String, view:IBaseView, options:Object)
		{
			_view = view;
			_options = options;
			_id = id;
		}
		public function get view():IBaseView{return _view;}
		public function get options():Object{return _options;}
		public function get id():String{return _id;}
		
		public function dispatchAction(aid:String, ...args):*{
			var sid:String = _id + "_" + aid;
			if(_moduleController.hasOwnProperty(sid)){
				return _moduleController[sid].apply(null,args);
			}else{
				return void;
			}
		}
		
		public function buildEnvironment():void{
			var result:* = dispatchAction("build");
			if(result is ResultProxy){
				ResultProxy(result).addProgressCallback(buildEnvironmentProgress);
				ResultProxy(result).addCompleteCallback(buildEnvironmentCompleted);
			}else if(result is Result){
				buildEnvironmentCompleted(result);
			}
		}
		public function buildEnvironmentProgress(result:Result):void{
			
		}
		public function buildEnvironmentCompleted(result:Result):void{
			
		}
	}
}